#include "MonWidgetGL.h"

MonWidgetGL::MonWidgetGL(int framesPerSecond, QWidget *parent, char *name): QGLWidget()
{
    setWindowTitle(QString::fromUtf8(name));
    if(framesPerSecond == 0)
        t_Timer = NULL;
    else
    {
        //widget->installEventFilter(this);
        //this->grabKeyboard();
        setFocusPolicy(Qt::StrongFocus);
        b_Fullscreen = false;
        int seconde = 1000; // 1 seconde = 1000 ms
        int timerInterval = seconde / framesPerSecond;
        t_Timer = new QTimer(this);
        connect(t_Timer, SIGNAL(timeout()), this, SLOT(timeOutSlot()));
        t_Timer->start( timerInterval );
    }
}

void MonWidgetGL::keyPressEvent(QKeyEvent *keyEvent)
{
    switch(keyEvent->key())
    {
    case Qt::Key_Escape:
        setWindowFlags(Qt::Widget);
        showNormal();
        b_Fullscreen = false;
        break;
    case Qt::Key_F1:
        toggleFullWindow();
        break;
    }
}

void MonWidgetGL::timeOutSlot()
{
    updateGL();
}

void MonWidgetGL::toggleFullWindow()
{
    if(b_Fullscreen)
    {
        setWindowFlags(Qt::Widget);
        showNormal();
        b_Fullscreen = false;
    }
    else
    {
        setWindowFlags(Qt::Window);
        showFullScreen();
        b_Fullscreen = true;
    }
}


